869B - The Eternal Immortality - CodeForces Solution


math *1100

Please click on ads to support us..

Python Code:

a, b = map(int, input().split())
if b - a > 10:
    print(0)
else:
    d = 1
    for i in range(a+1, b+1):
        d = d * i % 10
    print(d)

C++ Code:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#define go() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const int M=1e9+7;
int add(int a,int b)
{
    return (a%M+b%M)%M;
}
ll multi(ll a,ll b,ll m)
{
    return (a%m*b%m)%m;
}
ll factorial(ll n,ll x)
{
    int ans=1;
    return ( x == 0 ) ? 1 : multi(n , factorial(n - 1 , x - 1) , 10);
    
}
int main()
{
    go();
    ll a,b; cin>>a>>b;
    ll x=b-a;
    if(x>10)    cout<<0<<endl;
    else        cout<<(factorial(b,x)%10);
}


Comments

Submit
0 Comments
More Questions

119A - Epic Game
703A - Mishka and Game
1504C - Balance the Bits
988A - Diverse Team
1312B - Bogosort
1616B - Mirror in the String
1660C - Get an Even String
489B - BerSU Ball
977C - Less or Equal
1505C - Fibonacci Words
1660A - Vasya and Coins
1660E - Matrix and Shifts
1293B - JOE is on TV
1584A - Mathematical Addition
1660B - Vlad and Candies
1472C - Long Jumps
1293D - Aroma's Search
918A - Eleven
1237A - Balanced Rating Changes
1616A - Integer Diversity
1627B - Not Sitting
1663C - Pōja Verdon
1497A - Meximization
1633B - Minority
688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It